#pragma once
#include "File\Record.h"
#include "Pattern\Subject.h"

typedef struct {
	size_t   size;
	uint8_t* pData;
}RecordQueueItem;


class CFileButler :
	public Subject
{
	friend class CHolder;

public:
	CFileButler();
	~CFileButler();


	uint16_t  mRecordingFlag;


	bool   IsRecording(){return mRecordingFlag > 0;}
	bool   IsRecording(RECORD_FILE_TYPE type) {return mRecordingFlag & (1 << (type));}

	bool   IsRecordFileReady(RECORD_FILE_TYPE type) {return mIsRecordFileReady[RECORD_ALARM==type?1:0];}

	bool       StartWork();
	void       StopWork();

	void       HandleStream(uint8_t* pData, uint32_t size);
	void       StartAutoRecord(RECORD_FILE_TYPE type);
	void       StopAutoRecord(RECORD_FILE_TYPE type);

	void       SetOwner(UINT16 owner) { ASSERT(owner < 7); mOwner = owner; mRecords[0].mOwner = owner; mRecords[1].mOwner = owner; }

	void       Write(uint16_t inx);

	CFile*     AllocRecordFile(RECORD_FILE_TYPE type);
	void       ReleaseRecordFile(RECORD_FILE_TYPE type);

private:
	UINT16     mOwner;
	HANDLE     mRecordThread;
	UINT       mRecordThreadPID;

	bool       mIsRecordFileReady[2];
	//bool       mIsRecording[2];
	CTime      mTimes[2];

	CRecord    mRecords[2];
	CFile      mFiles[2];


	uint16_t   mQueueCursor;
	RecordQueueItem   mRecordQueue[RECORD_QUEUE_LENGTH];

//	CFile* AllocRecordFile();
//	void   ReleaseRecordFile();
//
//	void   SetContext(UINT owner ,RECORD_FILE_TYPE type);
//
//	void   UpdateStatus();
//
//

//
//protected:
//	CFile                   mFile;
//	//CFileRecordInfo         mRecordInfo;
//	CRecord                 mRecord;
//	CString                 mDirectory;
};

